package com.panshi.modules.controller;


import com.panshi.modules.service.ThLogService;
import com.panshi.vo.R;
import com.panshi.vo.ThLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器 :日志
 * </p>
 *
 * @author 857
 * @since 2020-07-29
 */
@Api(tags = "日志")
@RestController
@CrossOrigin
@RequestMapping("/api/sys/log")
public class ThLogController {

    @Autowired
    private ThLogService thLogService;

    @GetMapping("/list")
    @ApiOperation("查看日志集合接口")
    public List<ThLog> listThLog(){
        return thLogService.listThLog();
    }

    @GetMapping("/{id}")
    @ApiOperation("ID获取日志信息接口")
    public ThLog getThLog(@PathVariable("id")Integer id){
        return thLogService.getThLog(id);
    }

    @PostMapping
    @ApiOperation("新增日志接口")
    public R addThLog(@RequestBody ThLog thLog){
        int result = thLogService.addThLog(thLog);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    @PutMapping
    @ApiOperation("编辑日志接口")
    public R editThLog(@RequestBody ThLog thLog){
        int result = thLogService.editThLog(thLog);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除日志接口")
    public R delThLog(@PathVariable("id")Integer id){
        int result = thLogService.delThLog(id);
        if(result > 0){
            return R.ok();
        }
        return R.error();
    }
}

